<?php
   /**
    * Model categoriaAfiliado 
    * @author natanael
    *
    */

	class mcategoriaafiliado extends Model {
		private $mTableName = 'OB_CategoriaAfiliado'; 

		public function __construct() {
			parent::Model();
			$this->load->database();
		}


		public function LoadCategoria() 
		{
	 		$result = $this->db->get_where($this->mTableName);
			return $this->GetPaisesArrayFromQueryResult($result);
		}
		
		public function loadCategoriaId($where){
			
			$result = $this->db->get_where($this->mTableName,$where);
			
			if ($result->num_rows() == 0)
			    return false;

			 return new categoriaA($result->row());  
		}

		public function GetCount() {
			return count($this->LoadCategoria());
		}

	    private function GetPaisesArrayFromQueryResult($result) {
			if ($result->num_rows() == 0)
				return false;

			$paises_arr = array();

			foreach ($result->result() as $record) {
				$paises_arr[] = new categoriaA($record);
			}

			return $paises_arr;
    	}
    	
    	public function addRegistro($date){
    	   
    	   if ($this->db->insert($this->mTableName,$date)){
    	       return true;	    	
    	   }else{
    	   	   return false;
    	   }	
    		
    	}
    	
    	public function delRegistro($where){
    		
            if($this->db->delete($this->mTableName,$where)){
            	return true;
            }else{
            	return false;
            }
            
    	}
    	
    	public function editRegistro($where,$data){
    		 
    	 if($this->db->update($this->mTableName,$data,$where)){
            	return true;
            }else{
            	return false;
            }
    		
    	}
    	
	}

	class categoriaA{
		private $mIdCategoria = 0;
		private $mNombreCategoria = "";

		function __construct($object) {
			     $this->setIdCategoria($object->idCategoria);
			     $this->setNombreCategoria($object->descriccion);
		}

		public function setIdCategoria($id_pais) {
			$this->mIdCategoria = $id_pais;
		}

		function getIdCategoria() {
			return $this->mIdCategoria;
		}

		function setNombreCategoria($nombre) {
			$this->mNombreCategoria = $nombre;
		}

		function getNombreCategoria() {
			return $this->mNombreCategoria;
		}
	}
?>